/**********************************************************************
* Filename: Aviao.java
* Created: 2013/05/30
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import org.quasar.airNova.persistenceLayer.Database;

import java.util.Set;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.SortedSet;

public class Aviao
{
	
	/***********************************************************
	* @return all instances of class Aviao
	***********************************************************/
	public static Set<Aviao> allInstances()
	{
		return Database.allInstances(Aviao.class);
	}
	
	private String modelo;
	private String nome;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Aviao()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param modelo the modelo to initialize
	* @param nome the nome to initialize
	**********************************************************************/
	public Aviao(String modelo, String nome)
	{
		this.modelo = modelo;
		this.nome = nome;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the modelo of the aviao
	**********************************************************************/
	public String modelo()
	{
		return modelo;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param modelo the modelo to set
	**********************************************************************/
	public void setModelo(String modelo)
	{
		this.modelo = modelo;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the aviao
	**********************************************************************/
	public String nome()
	{
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE getter for Aviao[*] <-> Capacidade[*]
	* @return the capacidade of the aviao
	**********************************************************************/
	public Set<Capacidade> capacidade()
	{
		Set<Capacidade> result = new HashSet<Capacidade>();
		for (Capacidade x : Capacidade.allInstances())
			if (x.aviao()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE setter for Aviao[*] <-> Capacidade[*]
	* @param capacidade the capacidade to set
	**********************************************************************/
	public void setCapacidade(Set<Capacidade> capacidade)
	{
		for (Capacidade x : capacidade)
			x.setAviao(this);
	}
	
	/**********************************************************************
	* MEMBER2MEMBER getter for Aviao[*] <-> Classe[*]
	* @return the classe of the aviao
	**********************************************************************/
	public Set<Classe> classe()
	{
		Set<Classe> result = new HashSet<Classe>();
		for (Capacidade x : Capacidade.allInstances())
			if (x.aviao()  ==  this)
				result.add(x.classe());
		return result;
	}
	
	/**********************************************************************
	* MEMBER2MEMBER setter for Aviao[*] <-> Classe[*]
	* @param classe the classe to set
	**********************************************************************/
	public void setClasse(Set<Classe> classe)
	{
		for (Classe t : classe)
			for (Capacidade x : Capacidade.allInstances())
				if (x.aviao() == this)
					x.setClasse(t);
	}
	
	/**********************************************************************
	* ONE2MANY getter for Aviao[1] <-> Realizacao[*] ordered
	* @return the realizacoes of the aviao
	**********************************************************************/
	public Set<Realizacao> realizacoes()
	{
		Set<Realizacao> result = new HashSet<Realizacao>();
		for (Realizacao x : Realizacao.allInstances())
			if (x.aviao()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY multiple setter for Aviao[1] <-> Realizacao[*] ordered
	* @param realizacoes the realizacoes to set
	**********************************************************************/
	public void setRealizacoes(SortedSet<Realizacao> realizacoes)
	{
		for (Realizacao x : realizacoes)
			x.setAviao(this);
	}
	
	/**********************************************************************
	* ONE2MANY single setter for Aviao[1] <-> Realizacao[*] ordered
	* @param realizacao the realizacao to add
	**********************************************************************/
	public void addRealizacoes(Realizacao realizacao)
	{
		realizacao.setAviao(this);
	}
	
	/**********************************************************************
	* User-defined operation specified in SOIL/OCL
	**********************************************************************/
	public int Lotacao()
	{
		//	TODO
		//	return self.capacidade->collectNested($e : Capacidade | $e.Lotacao())->sum
		return -1;
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Aviao [modelo=" + modelo + ", nome=" + nome + "]";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv aviaoOrdemDeRealizacoesCanceladosSaoOsMaisAntigos
		(self.realizacoes->last.cancelada = true)
	
	*/
}
